package pt.iscte.poo.phonebook;
import java.util.HashMap;

public class Phonebook {
	private HashMap<String, Integer> nomeParaNumero = new HashMap<String, Integer>();
	private HashMap<Integer, String> numeroParaNome = new HashMap<Integer, String>();

	public void addEntry(final String name, int number) {
		nomeParaNumero.put(name, number);
		numeroParaNome.put(number, name);
	}

	 public String getName(int number) {
		 return numeroParaNome.get(number);
	 }
	
	 public int getNumber(final String name) {
		 return nomeParaNumero.get(name);
	 }
	 
	public void remove(final String name) {
		numeroParaNome.remove(nomeParaNumero.get(name));
		nomeParaNumero.remove(name);
	}

	public boolean contains(int number) {
		
		return numeroParaNome.containsKey(number);
	}
	
	public String toString() {
		String texto = "";
//		return nomeParaNumero.toString();
		for (String nome : nomeParaNumero.keySet()) {
			texto += nome + " -> " + nomeParaNumero.get(nome)
					+ System.lineSeparator(); // "\n";
		}
		return texto;
	} 
}
